package drive.Controller;

import drive.Model.RoadDisaster;
import drive.Service.ServiceInterface.RoadDisasterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/roadDisaster")
public class RoadDisasterController {

    @Autowired
    private RoadDisasterService roadDisasterService;

    @GetMapping()
    public String getAllRoadDisasters() {
        return roadDisasterService.findAll();
    }

    @GetMapping("/{disasterID}")
    public String getRoadDisasterByDisasterID(@PathVariable("disasterID") Integer disasterID) {
        return roadDisasterService.findByDisasterID(disasterID);
    }

    @GetMapping("/user/{userID}")
    public String getRoadDisastersByUserID(@PathVariable("userID") Integer userID) {
        return roadDisasterService.findByUserID(userID);
    }

    @PostMapping()
    public String addRoadDisaster(@RequestBody RoadDisaster roadDisaster) {
        return roadDisasterService.add(roadDisaster);
    }

    @PutMapping()
    public String updateRoadDisaster(@RequestBody RoadDisaster roadDisaster) {
        return roadDisasterService.update(roadDisaster);
    }

    @DeleteMapping("/{disasterID}")
    public String deleteRoadDisaster(@PathVariable("disasterID") Integer disasterID) {
        return roadDisasterService.delete(disasterID);
    }
}